﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Hygeia.Server.DAL
{
    public interface IRepository<TEntity> where TEntity : class
    {
        int Count { get; }
        //************编辑**************
        TEntity Add(TEntity t);
        TEntity Update(TEntity t);
        int Delete(TEntity t);
        int Delete(Expression<Func<TEntity, bool>> predicate);

        //************查询**************
        IQueryable<TEntity> GetAll();
        IQueryable<TEntity> LoadEntities(Expression<Func<TEntity, bool>> predicate);
        IQueryable<TEntity> LoadPageEntities(Expression<Func<TEntity, bool>> predicate, out int totalCount, int pageIndex = 1, int pageSize = 20);
        TEntity FirstOrDefault(Expression<Func<TEntity, bool>> predicate);
        bool Contains(Expression<Func<TEntity, bool>> predicate);
        TEntity Find(params object[] keys);
        int CountWithCondition(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// Get the object by execute the raw sql statements.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        IQueryable<TEntity> GetWithRawSql(string query, params object[] parameters);
    }
}
